package com.tech.test.dubbo.filter;

import static org.apache.dubbo.common.constants.CommonConstants.CONSUMER;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;

/**
 * 使用 OneWay模式
 * 
 * @author DELL
 */
@Activate(group = { CONSUMER })
public class OneWayFilter implements Filter, Filter.Listener {

	@Override
	public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
		Object oneway = RpcContext.getContext().get(org.apache.dubbo.rpc.Constants.RETURN_KEY);
		if (oneway != null && Boolean.FALSE.equals(oneway)) {
			invocation.setAttachment(org.apache.dubbo.rpc.Constants.RETURN_KEY, "false");
		}
		return invoker.invoke(invocation);
	}

	@Override
	public void onResponse(Result appResponse, Invoker<?> invoker, Invocation invocation) {

	}

	@Override
	public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {

	}
}
